const fs = require('fs');
const url = require('url');
const controller = require('./controller');
module.exports = (req, res) => {
  if (req.method === 'GET') {
    console.log(url.parse(req.url, true));
    if (req.url === '/') {
      controller.index(res);
    } else {
      fs.readFile('./test-img.jpg', function (err, data) {
        res.end(data);
      });
    }
  } else if (req.method === 'POST') {
    let acceptData = '';
    req.on('data', function (chunk) {
      acceptData += chunk;
    });
    req.on('end', function () {
      controller.user(require('querystring').parse(acceptData), res);
    });
    res.end();
  }
};
